{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "criterion = nn.CrossEntropyLoss()\n",
    "\n",
    "preds = []\n",
    "labels = []\n",
    "\n",
    "allLabels = []\n",
    "allPreds = []\n",
    "        \n",
    "with torch.no_grad():\n",
    "    for valSet, text in tqdm(x_test):\n",
    "        idxs = f(5,len(valSet))\n",
    "        trees = [ valSet[idx] for idx in idxs ]\n",
    "        \n",
    "        predicted = model(trees,text)\n",
    "        preds.append(predicted)\n",
    "#         print(predicted)\n",
    "        predicted =  torch.softmax(predicted,0)\n",
    "        predicted = torch.max(predicted, 0)[1].cpu().numpy().tolist()\n",
    "\n",
    "        labels.append(labelMap[finalTree.root.label])\n",
    "\n",
    "        allLabels.append(labelMap[finalTree.root.label])\n",
    "        allPreds.append(predicted)\n",
    "\n",
    "    predTensor = torch.stack(preds)\n",
    "    labelTensor = torch.tensor(labels).to(device)\n",
    "\n",
    "    print(allLabels,allPreds)\n",
    "\n",
    "    loss = criterion(predTensor.reshape(-1,4), labelTensor.reshape(-1))\n",
    "\n",
    "cr = classification_report(allLabels,allPreds,output_dict=True)\n",
    "cr['loss'] = loss.item()\n",
    "cr['Acc'] = accuracy_score(allLabels,allPreds,)\n",
    "\n",
    "print('val loss: ',cr['loss'])\n",
    "print(cr['Acc'])\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fakenews",
   "language": "python",
   "name": "fakenews"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
